package com.lanou.dllo.findfood.tools;

import android.app.ActionBar;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.GridLayout;
import android.widget.TextView;

import com.lanou.dllo.findfood.R;

/**
 * Created by dllo on 15/11/3.
 */
public class ActionBarManager {
    public static void initBackTitle(Context mContext,ActionBar actionBar,String strCenterTitle){
        actionBar.setTitle("返回");
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(true);
        initTitleCenterActionBar(mContext,actionBar,strCenterTitle);
    }
    public static void initTitleCenterActionBar(Context mContext,ActionBar actionBar,String strCenterTitle){
        LayoutInflater inflator = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View centerTitle = inflator.inflate(R.layout.view_actionbar_title, null);
        TextView title = (TextView) centerTitle.findViewById(R.id.actionbar_title);
        title.setText(strCenterTitle);
        ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(GridLayout.LayoutParams.WRAP_CONTENT, GridLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;

        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(centerTitle, layoutParams);
    }

}
